package adc.budget.ui.web.wicket.account;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SimpleFormComponentLabel;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.ResourceModel;

import adc.app.ui.wicket.BoEditPanel;
import adc.app.ui.wicket.model.DomainObjectListModel;
import adc.budget.spec.bo.IAccount;
import adc.budget.spec.bo.IAccountType;
import adc.budget.spec.bs.IAccountTypeBs;
import adc.budget.ui.web.wicket.IMsgsMisc;

public class AccountEditPanel extends BoEditPanel<IAccount> {

    private static final long serialVersionUID = 1L;

    public AccountEditPanel(String id) {
        super(id);
    }

    @Override
    protected void addFields(Form<IAccount> form) {
        final TextField<String> tfName = new TextField<String>("name");
        final DropDownChoice<IAccountType> ddlType = new DropDownChoice<IAccountType>("type",
                new DomainObjectListModel<IAccountType>(IAccountTypeBs.class), 
                new ChoiceRenderer<IAccountType>("name", "id"));
        final TextField<Double> tfStartingBalance = new TextField<Double>("startingBalance");
        tfStartingBalance.setType(Double.class);
        final TextArea<String> taNotes = new TextArea<String>("notes");
        
        tfName.setLabel(new ResourceModel(IMsgsMisc.NAME));
        ddlType.setLabel(new ResourceModel(IMsgsMisc.TYPE));
        tfStartingBalance.setLabel(new ResourceModel(IMsgsAccount.STARTING_BALANCE));
        taNotes.setLabel(new ResourceModel(IMsgsMisc.NOTES));
        
        form.add(tfName).add(ddlType).add(tfStartingBalance).add(taNotes);
        form.add(new SimpleFormComponentLabel("nameLbl", tfName));
        form.add(new SimpleFormComponentLabel("typeLbl", ddlType));
        form.add(new SimpleFormComponentLabel("startingBalanceLbl", tfStartingBalance));
        form.add(new SimpleFormComponentLabel("notesLbl", taNotes));
    }
}
